<?php
session_start();

$_SESSION['sections']=array();

require("../../../weblinx/weblinx.php");
require("../../Classes/Setter.php");
require("../../Classes/Sentinel.php");

require("../../Forms/UserServices/FrmAccess.php");
require("../../Forms/UserServices/FrmUserServices.php");

require("../../Forms/Admin/FrmAdmin.php");
require("../../Forms/Invitados/FrmInvitados.php");
require("../../Classes/Admin/User.php");

$setter=new Setter("../../Config");

$page=new Page();
$page->setCss("../../Themes/".$setter->getTheme()."/skin.css");

$page->start();
$page->headEnd();
$page->bodyStart();

if(isset($_POST['aceptar'])){
	$sentinel=new Sentinel();
	$r=$sentinel->NickPasswordVerify($_POST['nick'],$_POST['password'],"usuarios","nick","password");
	
	if($r==true){
		$_SESSION['nick']=$_POST['nick'];
		
		//Hallar secciones a las que tiene derecho
		$dbOperator=new DbOperator($setter->getDataBaseHost(),$setter->getDataBaseUserName(),$setter->getDataBaseName(),$setter->getDataBasePassword());
		$dbOperator->connect();
		$idRol1=$dbOperator->consult("SELECT idRol FROM usuarios WHERE nick='".$_POST['nick']."'","yes");
		$sections=$dbOperator->consult("SELECT seccion FROM permisos WHERE idRol='".$idRol1[0]."'","yes");
		
		$_SESSION['sections']=$sections;
		
		//Hallar id de usuario
		$idUser=$dbOperator->consult("SELECT id FROM usuarios WHERE nick='".$_POST['nick']."'","yes");
		$_SESSION['idUser']=$idUser[0];
		
		$frmUserService=new FrmUserServices();
		$frmUserService->show();
	}
	else{
		$frmAccess=new FrmAccess();
		$frmAccess->setErrorMessage("Nick y/o password incorrectos!!!");
		$frmAccess->show();
				
	}
}
if(isset($_POST['invitado'])){
	$_SESSION['sections']=array("Invited");
	$frmUserService=new FrmUserServices();
	$frmUserService->show();
}

$page->end();
?>